package com.jianganming.bridge;

/**
 * 商店购买包-->包-->颜色
 */
public class BridgeTest {
    public static void main(String[] args) {
        AbstractShop shop = new BeijingShop(new HandBag(new YellowColor()));
        shop.show();
        //System.out.println("---------------");
        //AbstractShop shop1 = new BeijingShop(new LvBag(new RedColor()));
        //shop1.show();
        //System.out.println("---------------");
        //AbstractShop shop2 = new BeijingShop(new LvBag(new YellowColor()));
        //shop2.show();
    }
}

interface Bag{
    void shop();
    Color getColor();
}

class HandBag implements Bag{
    Color color;
    public HandBag(Color color){
        this.color=color;
    }
    @Override
    public void shop() {
        System.out.println("HandBag包");
    }

    public Color getColor() {
        return color;
    }
}

class LvBag implements Bag{
    Color color;
    public LvBag(Color color){
        this.color=color;
    }
    @Override
    public void shop() {
        System.out.println("LvBag包");
    }
    public Color getColor() {
        return color;
    }
}

interface Color{
    void color();
}

class RedColor implements Color{
    public void color(){
        System.out.println("红色");
    }
}

class YellowColor implements Color{
    public void color(){
        System.out.println("黄色");
    }
}

abstract class AbstractShop{
    protected Bag bag;
    public AbstractShop(Bag bag){
        this.bag=bag;
    }
    public abstract void show();
}
//桥接对象
class BeijingShop extends AbstractShop{
    public BeijingShop(Bag bag){
        super(bag);
    }
    @Override
    public void show() {
        System.out.println("购买开始...");
        bag.shop();
        bag.getColor().color();
        System.out.println("购买结束...");
    }
}

